package com.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dao.UrlDao;
import com.enetiy.Urls;
import com.enetiy.Urlsver;

public class UrlsDaoImpl extends HibernateDaoSupport implements UrlDao {
	
	public List<Urlsver> sleUrlsList(int request,int aeraid,int isOk,int verid) throws Exception {
		String sql = "SELECT ue.* FROM urls AS ur, urlsver AS ue WHERE " +
				"ur.id = ue.urlsid AND " +
				"ur.request=? AND " +
				"ue.area_id=? AND " +
				"ur.isvolid=? AND " +
				"ue.is_valid=? AND " +
				"ue.verid = ? " +
				"ORDER BY ue.url_order";
		Query query = this.getSession().createSQLQuery(sql).addEntity(Urlsver.class);
		query.setParameter(0, request);
		query.setParameter(1, aeraid);
		query.setParameter(2, isOk);
		query.setParameter(3, isOk);
		query.setParameter(4, verid);
		List <Urlsver> list = query.list();
		return list;
	}
	
	public Urls sleUrlsId(int id) throws Exception {
		Urls u =this.getHibernateTemplate().get(Urls.class, id);
		return u;
	}
	
	public void updateUrl(Urls u) throws Exception {
		this.getHibernateTemplate().update(u);	
	}

	
	public void deleteUrl(Urls u) throws Exception {
		this.getHibernateTemplate().delete(u);	
	}

	
	public void insertUrl(Urls u) throws Exception {
		this.getHibernateTemplate().save(u);		
	}
}
